package cn.stylefeng.guns.modular.usr.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.usr.entity.Favor;
import cn.stylefeng.guns.modular.usr.model.params.FavorParam;
import cn.stylefeng.guns.modular.usr.service.FavorService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 新闻收藏控制器
 *
 * @author 
 * @Date 2019-12-17 17:27:48
 */
@Controller
@RequestMapping("/favor")
public class FavorController extends BaseController {

    private String PREFIX = "/favor";

    @Autowired
    private FavorService favorService;

    /**
     * 跳转到主页面
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/favor.html";
    }

    /**
     * 新增页面
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/favor_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/favor_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(FavorParam favorParam) {
        this.favorService.add(favorParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(FavorParam favorParam) {
        this.favorService.update(favorParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(FavorParam favorParam) {
        this.favorService.delete(favorParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 
     * @Date 2019-12-17
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(FavorParam favorParam) {
        Favor detail = this.favorService.getById(favorParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 
     * @Date 2019-12-17
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(FavorParam favorParam) {
        return this.favorService.findPageBySpec(favorParam);
    }

}


